package com.beesoft.demo.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResponse<T> {
    private List<T> data;
    private long total;
    private int page;
    private int perPage;
    private int totalPages;
    private boolean hasNext;
    private boolean hasPrevious;

    public static <T> PageResponse<T> of(List<T> data, long total, int page, int perPage) {
        int totalPages = (int) Math.ceil((double) total / perPage);
        return new PageResponse<>(
                data,
                total,
                page,
                perPage,
                totalPages,
                page < totalPages,
                page > 1
        );
    }
}

